function plusReady() {
	window.addEventListener('show', function(event) {
		init();
	});
	window.addEventListener('preshow', function(event) {
		init();
	});
	mui.get(base_url+'api/user/getaddress',{
			
		},function(data){
			console.log(data.code);
			if(data.code == 0){
				console.log(data.data.name);
				$('.lianxiren').val(data.data.name);
				$('.mobile').val(data.data.mobile);
				$('.xiaoqu').val(data.data.xiaoqu);
				$('.dizhi').val(data.data.address);
			}
		},'json'
	);
	$('#save-btn').on('click',function(){
		var name = $('.lianxiren').val();
		if(name == ""){
			mui.alert("姓名不得为空");
			return false;
		}
		var mobile = $('.mobile').val();
		if(mobile == ""){
			mui.alert("手机号码不得为空");
			return false;
		}
		var xiaoqu = $('.xiaoqu').val();
		if(xiaoqu == ""){
			mui.alert("小区不得为空");
			return false;
		}
		var dizhi = $('.dizhi').val();
		if(dizhi == ""){
			mui.alert("地址不得为空");
			return false;
		}
		mui.get(base_url+'api/user/saveaddress',{
				'name':name,
				'mobile':mobile,
				'xiaoqu':xiaoqu,
				'address':dizhi,
			},function(data){
				mui.alert(data.msg);
			},'json'
		);
		
	});
}

function init() {
	plus.navigator.setStatusBarBackground("#27b6f0");
	is_login();
	if(plus.storage.getItem('mobile') == 0) {
		openNewWindows('login.html');
		return false;
	}
	mui.get(base_url+'api/user/getaddress',{
			
		},function(data){
			console.log(data.code);
			if(data.code == 0){
				console.log(data.data.name);
				$('.lianxiren').val(data.data.name);
				$('.mobile').val(data.data.mobile);
				$('.xiaoqu').val(data.data.xiaoqu);
				$('.dizhi').val(data.data.address);
			}
		},'json'
	);
}
document.addEventListener("plusready", plusReady, false);